Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wasm-metadata] parse OCI author custom section #1925

Merged

Conversation

yoshuawuyts
Copy link
Member

This PR adds support for parsing the author custom section, implementing parts of #1922. Thanks!

Draft Notes

I'm filing this PR early and as a draft because I'm not 100% sure I'm following best practices here. It's my first time using wasmparser and wasm-encoder, and I'm for example not sure whether parse_wasm should take a BinaryReader or CustomSectionReader.

Also: I was looking for something like a Parse trait, but I don't think wasmparser has one? I quite liked the encoder side of things.

Finally: in this PR I'm basically just wrapping CustomSection in a newtype - however that means storing the internal data as a byte array rather than a string. How do we feel about that?

I'm asking these questions since I'm planning to repeat this pattern a number of times for the other custom sections, and it seems worth making sure it's early on. Thanks!

Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! What I might recommend is to take the &[u8] entire wasm in memory as opposed to just a custom section. That way you can bake in how to handle a missing section, duplicated sections, the section name, etc. Internally you can use a BinaryReader to parse the binary data if necessary, but yeah the Parse-trait side of things is sort of there with FromReader but it's no the same as the encoding side of things.

@yoshuawuyts yoshuawuyts force-pushed the refactor-registry-metadata branch from 801338f to 06f9aa0 Compare December 4, 2024 16:54
@yoshuawuyts yoshuawuyts marked this pull request as ready for review December 4, 2024 16:55
Comment on lines 59 to 65
rewrite_wasm(
&self.name,
&Producers::from_meta(self),
&self.author,
self.registry_metadata.as_ref(),
input,
)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The number of function arguments will continue to increase until morale improves.

More seriously though: once I finish adding the custom sections, I plan to refactor the way we handle this. I suspect we can combine rewrite_wasm, Metadata, and AddMetadata into a unified structure, allowing us to tidy this up.

Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me, thanks for this!

@alexcrichton alexcrichton added this pull request to the merge queue Dec 4, 2024
Merged via the queue into bytecodealliance:main with commit b2e621d Dec 4, 2024
30 checks passed
@yoshuawuyts yoshuawuyts deleted the refactor-registry-metadata branch December 4, 2024 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants